﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TowerDefense.Navigation
{
    public class Node : TowerDefense.Actors.Actor, IComparable
    {
        //Represents the path network
        public List<Node> connected = new List<Node>();
        public Location location;

        public Node(Location start)
            : base(start)
        {
            
        }

        public void ConnectTo(Node node) //connects 1-way, A to B, not also B to A
        {
            if(!this.connected.Contains(node))
                this.connected.Add(node);
        }

        public void DissconectFrom(Node node)
        {
            this.connected.Remove(node);
        }

        public void BiDirectionalConnect(Node node)
        {
            this.ConnectTo(node);
            node.ConnectTo(this);
        }

        public void BiDirectionalDisconnect(Node node)
        {
            this.DissconectFrom(node);
            node.DissconectFrom(this);
        }

        public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, Location location)
        {
            base.Draw(spriteBatch, location);

            foreach(var node in this.connected)
            {
                //TODO: draw a line between each connection
            }
        }

        public int GetDistance()
        {
            return
                (int)Math.Sqrt(Math.Pow(this.location.getCol() - goal.getCol(), 2) +
                          Math.Pow(this.location.getRow() - goal.getRow(), 2));
        }

        public int CompareTo(object obj)
        {
            if (this.GetDistance() > ((Node)obj).GetDistance())
                return -1;
            else if (this.GetDistance() < ((Node)obj).GetDistance())
                return 1;
            else
            {
                return 0;
            }
        }
    }
}
